package com.smfx.yxt.view;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

import com.smfx.yxt.model.TermInfo;
import com.smfx.yxt.utils.StringUtil;

public class TermView extends TermInfo {
	
	private static final long serialVersionUID = 2414849224346649L;
	
	private Map<Integer, String> gradeMap;
	
	/**
	 * 毕业年
	 */
	private Integer finishYear;
	
	private Integer termKey;
	
	public Map<Integer, String> getGradeMap() {
		return gradeMap;
	}
	
	public void setGradeMap(Map<Integer, String> gradeMap) {
		this.gradeMap = gradeMap;
	}

	public String getGradeName(Integer grade) {
		String gradeName = this.gradeMap.get(grade);
		if(StringUtils.isBlank(gradeName)) {
			return "已毕业" + grade + "级";
		}
		return gradeName;
	}

	public Integer getFinishYear() {
		if(finishYear == null) {
			init();
		}
		return finishYear;
	}

	public void setFinishYear(Integer finishYear) {
		this.finishYear = finishYear;
	}

	public Integer getTermKey() {
		return termKey;
	}

	public void setTermKey(Integer termKey) {
		this.termKey = termKey;
	}
	public void init() {
		if(gradeMap == null) {
			String termName = super.getTermName();
			Integer grade = Integer.valueOf(termName.substring(0, termName.indexOf("-")));
			Map<Integer, String> map = new HashMap<>();
			map.put(grade.intValue() - 5, "六年级");
			map.put(grade.intValue() - 4, "五年级");
			map.put(grade.intValue() - 3, "四年级");
			map.put(grade.intValue() - 2, "三年级");
			map.put(grade.intValue() - 1, "二年级");
			map.put(grade, "一年级");
			this.gradeMap = map;
			this.termKey = grade;
			this.finishYear = grade - 6;
		}
	}
}
